package com.android.plc.util;

import android.content.Context;
import android.content.res.Resources;

import com.android.plc.CONST.DEVICETYPE;
import com.android.plc.R;

public class StringUtil
{
	public static String convRoomCode(Context context, int pos)
	{
		String format = context.getString(R.string.room_code_format);
		return String.format(format, convCode(pos));
	}

	public static String convDeviceCode(Context context, int pos)
	{
		String format = context.getString(R.string.device_code_format);
		return String.format(format, convCode(pos / 16) + (pos % 16 + 1));
	}

	public static String convCode(int pos)
	{
		return Character.toString((char) ('A' + pos));
	}

	public static String convDeviceType(Context context, int type, int subtype)
	{
		String format = context.getString(R.string.device_type_format);
		return String.format(format, convDeviceType(type, subtype));
	}

	private static String convDeviceType(int type, int subtype)
	{
		if (type < 0 || type >= Types.length)
			return null;

		if (subtype >= 0 && subtype < Sub_Types[type].length && !Sub_Types[type][subtype].isEmpty())
		{
			return Sub_Types[type][subtype];
		}
		return Types[type];
	}

	public static String[][] Sub_Types;
	public static String[] Types = null;

	public static void initTypes(Context context)
	{
		if (Types == null && Sub_Types == null)
		{
			Resources resources = context.getResources();
			Types = resources.getStringArray(R.array.device_type);
			int size = Types.length;
			Sub_Types = new String[size][];
			Sub_Types[DEVICETYPE.DEVICETYPE_IR] = resources.getStringArray(R.array.sub_type_ir);
			Sub_Types[DEVICETYPE.DEVICETYPE_DEFAULT] = resources.getStringArray(R.array.sub_type_default);
			Sub_Types[DEVICETYPE.DEVICETYPE_DIM] = resources.getStringArray(R.array.sub_type_dim);
			Sub_Types[DEVICETYPE.DEVICETYPE_AIR_CONDITION] = resources.getStringArray(R.array.sub_type_air);
		}
	}
}
